package cursorn.web;

/**
 * $author ted
 */
public class RequestScope {
    private final PageDependencies pageDependencies = new PageDependencies();
    public static final ThreadLocal<RequestScope> current = new ThreadLocal<RequestScope>();

    public static PageDependencies pageDependencies() {
        RequestScope requestScope = getCurrentRequestScope();
        return requestScope.pageDependencies;
    }

    private static RequestScope getCurrentRequestScope() {
        RequestScope requestScope = current.get();
        if(requestScope == null) {
            System.out.println("New request scope was created");
            requestScope = new RequestScope();
            current.set(requestScope);
        }
        return requestScope;
    }
}
